package com.example.shortlink.dao.mapper;

import com.example.shortlink.dao.entity.LinkAccessStats;
import com.mybatisflex.core.BaseMapper;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;

public interface LinkAccessStatsMapper extends BaseMapper<LinkAccessStats> {

    @Insert("<script> " +
            "INSERT INTO " +
            "t_link_access_stats " +
            "(" +
            "full_short_url, " +
            "gid, " +
            "date, " +
            "pv, " +
            "uv, " +
            "uip, " +
            "hour, " +
            "weekday, " +
            "create_time, " +
            "update_time, " +
            "del_flag" +
            ") " +
            "VALUES " +
            "( " +
            "#{linkAccessStats.fullShortUrl}, " +
            "#{linkAccessStats.gid}, " +
            "#{linkAccessStats.date}, " +
            "#{linkAccessStats.pv}, " +
            "#{linkAccessStats.uv}, " +
            "#{linkAccessStats.uip}, " +
            "#{linkAccessStats.hour}, " +
            "#{linkAccessStats.weekday}, " +
            "NOW(), " +
            "NOW(), " +
            "0" +
            ") " +
            "ON DUPLICATE KEY UPDATE pv = pv +  #{linkAccessStats.pv}, " +
            "uv = uv + #{linkAccessStats.uv}, " +
            " uip = uip + #{linkAccessStats.uip}" +
            "</script>")
    void shortLinkStats(@Param(value = "linkAccessStats") LinkAccessStats linkAccessStats);


}